
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.MajorClassDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class MajorClassDaoJdbc extends BaseDaoJdbc implements MajorClassDao {
	String tableName="T_MAJOR_CLASS";
	String beanName="majorClass";
	
	public CommonBean createMajorClass(){
		CommonBean majorClasss=this.createBean(tableName,beanName);
                return majorClasss;		
	}
	
/*
	public CommonBean findMajorClasss(String refid) {
		CommonBean majorClasss=this.createMajorClass();
		String sql="select * from T_MAJOR_CLASS where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		majorClasss.addData(data);
                return majorClasss;
       }
*/
	public CommonBean findMajorClassById(String id) {
		CommonBean majorClasss=this.createMajorClass();
		String sql="select * from T_MAJOR_CLASS where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		majorClasss.addData(data);
    return majorClasss;
  }
  
	public CommonBean findValidMajorClasss() {
		CommonBean majorClasss=this.createMajorClass();
		String sql="select t.* from T_MAJOR_CLASS t WHERE exists(select * from T_GRADE_MAJOR where grade+num_year>=convert(char(4),getdate(),120) and id=t.refid) ";
		List data=this.getCommonDao().select(sql,new String[]{});
		majorClasss.addData(data);
    return majorClasss;
  }
	public void insertMajorClass(CommonBean majorClassBean){
		List data=majorClassBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}
	public void updateMajorClass(CommonBean majorClassBean){
		List data=majorClassBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchUpdate(row,data);
	}
}

